﻿using Sasc.PV.BLL.ZhuDing;
using Sasc.PV.DAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Sasc.PV.Web.Admin.Zhuding
{
    public partial class PenTuModify : PVGongXuAdminPage<ZhuDingCheJianManagement,ZhuDingPenTuGongXu,ZhuDingGongXuTarget>
    {
        #region PageLoad
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!HasPermission(GongXuQuanXianLeiXing.MODIFY))
                MessageBox.ShowAndRedirect(this, "对不起，没有权限访问该页面。", "PenTu");

            if (!IsPostBack)
            {
                var model = new PvZDPenTu();
                model = model.GetModel(int.Parse(Request.QueryString["ID"].ToString()));
                DanHuaGuiAmountTextBox.Text = model.DanHuaGuiAmount.ToString();
                DanHuaGuiPiCiTextBox.Text = model.DanHuaGuiPiCi;
                DanHuaGuiPinPaiTextBox.Text = model.DanHuaGuiPinPai;
                FuChaUserTextBox.Text = model.FuChaUser;
                GanGuoBianHaoTextBox.Text = model.GanGuoBianHao;
                GanGuoPiCiTextBox.Text = model.GanGuoPiCi;
                GanGuoPinPaiTextBox.Text = model.GanGuoPinPai;
                GanGuoXingHaoTextBox.Text = model.GanGuoXingHao;
                GuiRongJiaoAmountTextBox.Text = model.GuiRongJiaoAmount.ToString();
                GuiRongJiaoPiCiTextBox.Text = model.GuiRongJiaoPiCi;
                GuiRongJiaoPinPaiTextBox.Text = model.GuiRongJiaoPinPai;
                JianChaNoteTextBox.Text = model.JianChaNote;
                PenTuDateTimeTextBox.Text = model.PenTuDateTime.Format();
                PenTuMaxTempTextBox.Text = model.PenTuMaxTemp.ToString();
                PenTuMinTempTextBox.Text = model.PenTuMinTemp.ToString();
                WaterAmountTextBox.Text = model.WaterAmount.ToString();
                CreatedByLabel.Text = model.CreatedBy;
                CreatedDateLabel.Text = model.CreatedDate.Format();
                LastUpdatedByLabel.Text = model.LastUpdatedBy;
                LastUpdatedDateLabel.Text = model.LastUpdatedDate.Format();
            }
        }
        #endregion

        #region GetQuanXianValue
        protected override string GetQuanXianValue()
        {
            return "102";
        }
        #endregion 
        
        #region Submit Button
        protected void SubmitImageButton_Click(object sender, ImageClickEventArgs e)
        { 
            var target = new ZhuDingGongXuTarget
            {
                GanGuoBianHao = GanGuoBianHaoTextBox.Text,
                XiaoDingBianHao = string.Empty
            };

            var model = new PvZDPenTu();
            model = model.GetModel(int.Parse(Request.QueryString["ID"].ToString()));
            if (model == null)
            {
                MessageBox.ShowAndRedirect(this, "《喷涂工序卡》修改成功！", "PenTu");
            }

            decimal parseDecimal = 0;
            DateTime parseDateTime = DateTime.Now;
             
            model.DanHuaGuiAmount = decimal.TryParse(DanHuaGuiAmountTextBox.Text, out parseDecimal) ? parseDecimal : 0;
            model.DanHuaGuiPiCi = DanHuaGuiPiCiTextBox.Text;
            model.DanHuaGuiPinPai = DanHuaGuiPinPaiTextBox.Text;
            model.FuChaUser = FuChaUserTextBox.Text;
            //model.GanGuoBianHao = GanGuoBianHaoTextBox.Text;
            model.GanGuoPiCi = GanGuoPiCiTextBox.Text;
            model.GanGuoPinPai = GanGuoPinPaiTextBox.Text;
            model.GanGuoXingHao = GanGuoXingHaoTextBox.Text;
            //model.//GongXuRecID ="";
            model.GuiRongJiaoAmount = decimal.TryParse(GuiRongJiaoAmountTextBox.Text, out parseDecimal) ? parseDecimal : 0;
            model.GuiRongJiaoPiCi = GuiRongJiaoPiCiTextBox.Text;
            model.GuiRongJiaoPinPai = GuiRongJiaoPinPaiTextBox.Text;
            model.JianChaNote = JianChaNoteTextBox.Text;
            model.LastUpdatedBy = LoginUserName;
            model.LastUpdatedDate = DateTime.Now;
            model.PenTuDateTime = DateTime.TryParse(PenTuDateTimeTextBox.Text, out parseDateTime) ? parseDateTime : DateTime.Now;
            model.PenTuMaxTemp = decimal.TryParse(PenTuMaxTempTextBox.Text, out parseDecimal) ? parseDecimal : 0;
            model.PenTuMinTemp = decimal.TryParse(PenTuMinTempTextBox.Text, out parseDecimal) ? parseDecimal : 0;
            model.WaterAmount = decimal.TryParse(WaterAmountTextBox.Text, out parseDecimal) ? parseDecimal : 0;


            CheJianGongXu.UpdateGongXuRec(model, target);

            MessageBox.ShowAndRedirect(this, "《喷涂工序卡》修改成功！", "PenTu");
        }
        #endregion

    }
}